package org.example.controller;


import org.example.domain.Result;
import org.example.domain.UtuFollower;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import org.example.domain.UtuFollowing;
import org.example.service.IUtuFollowingService;

import java.util.List;

/**
 * 关注信息Controller
 *
 * @author coderfun
 * @date 2024-12-04
 */
@RestController
@RequestMapping("/user_to_user/following")
public class UtuFollowingController {
    @Autowired
    private IUtuFollowingService utuFollowingService;

    /**
     * 查询关注信息列表
     */
//    @PreAuthorize("@ss.hasPermi('system:following:list')")
//    @GetMapping("/list")
//    public TableDataInfo list(UtuFollowing utuFollowing)
//    {
//        startPage();
//        List<UtuFollowing> list = utuFollowingService.selectUtuFollowingList(utuFollowing);
//        return getDataTable(list);
//    }

    /**
     * 获取关注信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:following:query')")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id) {
        return Result.success(utuFollowingService.selectUtuFollowingById(id));
    }

    /**
     * 新增关注信息
     */
    @PreAuthorize("@ss.hasPermi('system:following:add')")
    @PostMapping
    public Result add(@RequestBody UtuFollowing utuFollowing) {
        return Result.success(utuFollowingService.insertUtuFollowing(utuFollowing));
    }

    /**
     * 修改关注信息
     */
    @PreAuthorize("@ss.hasPermi('system:following:edit')")
    @PutMapping
    public Result edit(@RequestBody UtuFollowing utuFollowing) {
        return Result.success(utuFollowingService.updateUtuFollowing(utuFollowing));
    }

    /**
     * 删除关注信息
     */
    @PreAuthorize("@ss.hasPermi('system:following:remove')")
    @DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids) {
        return Result.success(utuFollowingService.deleteUtuFollowingByIds(ids));
    }

    /**
     * 查询用户的关注列表
     */
    @PreAuthorize("@ss.hasPermi('system:follower:add')")
    @PostMapping("/list")
    public Result selectFlowingList(@RequestBody UtuFollower utuFollower) {
        List<UtuFollowing> ans = utuFollowingService.selectFlowingList(utuFollower);
        return Result.success(ans);
    }
}
